package com.ygp;

import java.util.*;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2021/08/27 <br>
 */
public class Normal {
    Map<String, String> map = new Hashtable<>();

    public static void main(String[] args) throws InterruptedException {
       /* Normal normal = new Normal();
        Thread thread1 = new Thread(normal::thread1, "thread1");
        Thread thread2 = new Thread(normal::thread2, "thread2");
        thread1.start();
        Thread.sleep(1000);
        thread2.start();
*/
    }


    private synchronized void thread1() {
        System.out.println("线程1开始执行");
        if (map.get("name") == null) {
            try {
                System.out.println("线程1将进入wait....");
                wait(20000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            map.put("name", "alai");
        }
        System.out.println(map.get("name"));
    }

    private synchronized void thread2() {
        System.out.println("线程2开始执行....");
        if (map.get("name") == null) {
            String name = Thread.currentThread().getName();
            map.put("name", "ocean");
        }
        System.out.println(map.get("name"));
    }
}
